// scripts/check_user_organizations.js
const { Sequelize } = require('sequelize');

// 数据库配置
const sequelize = new Sequelize('lingxi_system', 'root', '888mei525', {
  host: '127.0.0.1',
  dialect: 'mysql',
  logging: false
});

async function checkUserOrganizations() {
  try {
    // 测试数据库连接
    await sequelize.authenticate();
    console.log('数据库连接成功');
    
    // 查询用户组织关联数据
    const [results] = await sequelize.query('SELECT * FROM user_organizations');
    
    console.log('\n用户组织关联数据:');
    if (results.length === 0) {
      console.log('没有找到用户组织关联数据');
    } else {
      console.log('ID\t用户ID\t组织ID\t角色\t状态');
      console.log('--\t------\t------\t--\t--');
      results.forEach(row => {
        console.log(`${row.id}\t${row.user_id}\t${row.organization_id}\t${row.role || 'N/A'}\t${row.status}`);
      });
    }
    
    await sequelize.close();
  } catch (error) {
    console.error('检查用户组织关联数据失败:', error.message);
  }
}

checkUserOrganizations();